package com.lzjn.code.web.entity;

import com.lzjn.code.common.base.BaseEntity;

import java.io.Serializable;

public class DataSource extends BaseEntity implements Serializable {

	private static final long serialVersionUID = 1L;

	private String id;
	private String description;
	private String dbType;
	private String dbName;
	private String server;
	private String port;
	private String username;
	private String password;
	
	public String getDiverName(){
		String diverName = null;
		
		if("mysql".equals(this.dbType)){
//			diverName = "com.mysql.jdbc.Driver";
			diverName = "com.mysql.cj.jdbc.Driver";
		}
		else if("oracle".equals(this.dbType)){
			diverName = "oracle.jdbc.driver.OracleDriver";
		}
		else if("sqlserver".equals(this.dbType)){
			diverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
		}
		
		return diverName;
	}
	
	public String getUrl(){
		String url = null;
		
		if("mysql".equals(this.dbType)){
			url = "jdbc:mysql://"+ this.server +":"+ this.port +"/"
				+ this.dbName +"?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&serverTimezone=GMT%2B8&useSSL=false";
		}
		else if("oracle".equals(this.dbType)){
			url = "jdbc:oracle:thin:@"+ this.server +":"+ this.port +":"+ this.dbName;
		}
		else if("sqlserver".equals(this.dbType)){
			url = "jdbc:sqlserver://"+ this.server +":"+ this.port +";DatabaseName="+ this.dbName;
		}
		
		return url;
	}
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public String getDbType() {
		return dbType;
	}
	public void setDbType(String dbType) {
		this.dbType = dbType;
	}
	public String getDbName() {
		return dbName;
	}
	public void setDbName(String dbName) {
		this.dbName = dbName;
	}
	public String getServer() {
		return server;
	}
	public void setServer(String server) {
		this.server = server;
	}
	public String getPort() {
		return port;
	}
	public void setPort(String port) {
		this.port = port;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}

	@Override
	public String toString() {
		return "DataSource [id=" + id + ", description=" + description + ", dbType=" + dbType + ", dbName=" + dbName
				+ ", server=" + server + ", port=" + port + ", username=" + username + ", password=" + password
				+ ", toString()=" + super.toString() + "]";
	}

	
}
